<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap -->
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="echarts.min.js"></script>
    <style >
    #main {
        height:500px;
        width: 1400px;
        margin: 20px auto;
    }
    </style>
</head>
<body>

    <h1 style="text-align: center;">期末作业 <small>可视化数据</small></h1>

    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    <div id="main"></div>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var dataAxis = ['1997', '1998', '1999', '2000', '2001', '2002', '2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016'];
var data = [10.06, 9.14, 8.18, 7.58, 6.95, 6.45, 6.01, 5.87, 5.89, 5.28, 5.17, 5.08, 4.87, 4.79, 4.79, 4.95, 4.92, 5.21, 4.96, 5.86];
var yMax = 10;
var dataShadow = [];

for (var i = 0; i < data.length; i++) {
    dataShadow.push(yMax);
}

option = {
    title: {
        text: '人口自然增长率(‰)',
        top:'top',
        left:'center',
        subtext: '点击缩放'
    },
    xAxis: {
        //type: 'category',
        //data: ['1997', '1998', '1999', '2000', '2001', '2002', '2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016',]
        data: dataAxis,
        axisLabel: {
            inside: true,
            textStyle: {
                color: '#fff'
            }
        },
        axisTick: {
            show: false
        },
        axisLine: {
            show: false
        },
        z: 10
    },
    yAxis: {
        axisLine: {
            show: false
        },
        axisTick: {
            show: false
        },
        axisLabel: {
            textStyle: {
                color: '#999'
            }
        }
    },
    dataZoom: [
        {
            type: 'inside'
        }
    ],
    series: [
        { // For shadow
            type: 'bar',
            itemStyle: {
                normal: {color: 'rgba(0,0,0,0.05)'}
            },
            barGap:'-100%',
            barCategoryGap:'40%',
            data: dataShadow,
            animation: false
        },
        {
            type: 'bar',
            itemStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(
                        0, 0, 0, 1,
                        [
                            {offset: 0, color: '#1c2894'},
                            {offset: 0.5, color: '#515dd1'},
                            {offset: 1, color: '#9bcaff'}
                        ]
                    )
                },
                emphasis: {
                    color: new echarts.graphic.LinearGradient(
                        0, 0, 0, 1,
                        [
                            {offset: 0, color: '#ce88fa'},
                            {offset: 0.7, color: '#8645bd'},
                            {offset: 1, color: '#5a317d'}
                        ]
                    )
                }
            },
            data: data
        }
    ]
};

// Enable data zoom when user click bar.
var zoomSize = 6;
myChart.on('click', function (params) {
    console.log(dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)]);
    myChart.dispatchAction({
        type: 'dataZoom',
        startValue: dataAxis[Math.max(params.dataIndex - zoomSize / 2, 0)],
        endValue: dataAxis[Math.min(params.dataIndex + zoomSize / 2, data.length - 1)]
    });
});

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>

<div class="panel panel-default" style="width: 1400px;text-align:center;margin:0px auto;font-family: 黑体">   

  <!-- Default panel contents -->
  <div class="panel-heading" >数据来源</div>

  <!-- Table -->
  <table class="table">
       国家数据   http://data.stats.gov.cn/easyquery.htm?cn=C01
  </table>
</div>



</body>
</html>
